package com.myweb.utils;

public class DesTools {

	private final static String DES_KEY="wyb.2016";//不要改变
	
	public static void main(String[] args) throws Exception {
		  System.out.println(encrypt("1561"));
		  System.out.println("MTQ5MHd5Yi4yMDE2>>解密="+decrypt("MTQ5MHd5Yi4yMDE2"));
	}
	/**
	 * 加密
	 * @param data
	 * @return
	 * @throws Exception
	 */
	public static String encrypt(String data) throws Exception {
		return encrypt(data, DES_KEY);
	}
	/**
	 * 根据键值进行加密
	 * @param data
	 * @param desKey 加密键byte数组
	 * @return
	 * @throws Exception
	 */

	public static String encrypt(String data, String desKey) throws Exception {
		return UrlBase64Coder.encode(data+desKey);
	}
	/**
	 * 解密
	 * @param data
	 * @return
	 * @throws Exception
	 */
	public static String decrypt(String data) throws Exception {
		if (data == null)
			return null;
		String value =  UrlBase64Coder.decode(data);
		
		return value.replace(DES_KEY, "");
	}
}
